package blogtest;

import org.junit.jupiter.api.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import javax.swing.plaf.SliderUI;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TaoBaoTest {
    static WebDriver webDriver;
    @BeforeAll
    static void init(){
        webDriver = new ChromeDriver();
    }
    @AfterAll
    static void quite(){
        webDriver.quit();
    }
    @Test
    @Order(1)
    void test() throws InterruptedException {
        webDriver.get("https://login.taobao.com/");
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.DAYS);
        webDriver.findElement(By.cssSelector("#header > div > h1 > a")).click();
        sleep(3000);
        String cur_handle = "";
        Set<String> handels = webDriver.getWindowHandles();
        for (String x:
             handels) {
            cur_handle = x;
        }
       // String cur_url = webDriver.getCurrentUrl();
       String name =  webDriver.findElement(By.cssSelector("body > div:nth-child(9) > div > div > div > h3 > span")).getText();
        Assertions.assertEquals("猜你喜欢", name);
        System.out.println("测试通过!");
        sleep(3000);
    }
    @Test
    @Order(2)
    void test02() throws InterruptedException {
        webDriver.findElement(By.xpath("/html/body/div[3]/div[2]/div[2]/div[2]/div[5]/div/div[2]/div[1]/a[2]")).click();
        Set<String> handels = webDriver.getWindowHandles();
        String cur_handle = "";
        for (String x:
                handels) {
            cur_handle = x;
        }
        webDriver.switchTo().window(cur_handle);
        webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
        String cur_name = webDriver.findElement(By.cssSelector("body > div.page > div > div > h2")).getText();
        Assertions.assertEquals("用户注册",cur_name);
        sleep(2000);
    }
}
